home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJTST200.ZIP / tests / libc / posix / unistd / tread.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-09  |  794 b   |  46 lines

  1. #include <stdio.h>
  2. #ifdef __GO32__
  3. #include <unistd.h>
  4. #endif
  5. #include <fcntl.h>
  6. #include <io.h>
  7. #include <sys/stat.h>
  8.  
  9. int
  10. main(int argc, char **argv)
  11. {
  12.   int f;
  13.   unsigned char buf[1000];
  14.   int r, i;
  15.  
  16.   if (argc < 2)
  17.   {
  18.     printf("usage: tread file\n");
  19.     return 1;
  20.   }
  21.  
  22.   printf("Binary:\n");
  23.   f = _open(argv[1], O_RDONLY);
  24.   while ((r=_read(f, buf, 1000)) > 0)
  25.   {
  26.     for (i=0; i<r; i++)
  27.       printf(" %02x", buf[i]);
  28.     printf(" - %d\n", lseek(f, 0L, 1));
  29.   }
  30.   _close(f);
  31.  
  32.   printf("Text:\n");
  33.   f = open(argv[1], O_RDONLY|O_TEXT);
  34.   while ((r=read(f, buf, 10)) > 0)
  35.   {
  36.     printf(" [%d]", r);
  37.     for (i=0; i<r; i++)
  38.       printf(" %02x", buf[i]);
  39.     printf(" <%d>", lseek(f, 0L, 1));
  40.   }
  41.   printf("\n");
  42.   close(f);
  43.  
  44.   return 0;
  45. }
  46.